# Contributor: Celeste <cielesti@protonmail.com>
# Contributor: qaqland <qaq@qaq.land>
# Maintainer: Celeste <cielesti@protonmail.com>
pkgname=ktistec
_pkgver=2.0.0-11
pkgver=${_pkgver/-/.}
pkgrel=0
pkgdesc="Single-user ActivityPub server written in Crystal"
url="https://github.com/toddsundsted/ktistec"
arch="x86_64 aarch64" # crystal
license="AGPL-3.0-or-later"
depends="tzdata"
makedepends="
	crystal
	libxml2-dev
	musl-utils
	openssl-dev
	shards
	sqlite-dev
	"
checkdepends="yaml-dev"
options="net"
install="$pkgname.pre-install"
pkgusers="ktistec"
pkggroups="ktistec"
subpackages="$pkgname-openrc"
source="$pkgname-$_pkgver.tar.gz::https://github.com/toddsundsted/ktistec/archive/refs/tags/v$_pkgver.tar.gz
	ktistec.initd
	ktistec.confd
	"
builddir="$srcdir/$pkgname-$_pkgver"

export CRYSTAL_CACHE_DIR="${CRYSTAL_CACHE_DIR:-"$srcdir/.cache"}"
export SHARDS_CACHE_PATH="${SHARDS_CACHE_PATH:-"$srcdir/.cache"}"

prepare() {
	default_prepare

	shards install --frozen
}

build() {
	crystal build --no-debug --release src/ktistec/server.cr
}

check() {
	crystal spec -v
}

package() {
	install -Dvm755 server "$pkgdir"/usr/bin/ktistec
	install -dvm750 -o ktistec -g ktistec "$pkgdir"/var/lib/ktistec

	cp -a etc public "$pkgdir"/var/lib/ktistec/
	ln -sv public/uploads "$pkgdir"/var/lib/ktistec/
	chown -R ktistec:ktistec "$pkgdir"/var/lib/ktistec/public/uploads

	install -Dm755 "$srcdir"/ktistec.initd "$pkgdir"/etc/init.d/ktistec
	install -Dm644 "$srcdir"/ktistec.confd "$pkgdir"/etc/conf.d/ktistec
}

sha512sums="
49c6a10d9a60280023089ae70e60f5357974d0ab478eacbbf8e738a5fa7de1890b34f0bae9acb27a58b1af429467aa9c5682f68381a8d74e74076cd76fbd6925  ktistec-2.0.0-11.tar.gz
f2520a9306daf544fec456e739abf1bb1e1a188992bbd8ef4a3ce3915a342209521ceedef8fc871c659d12ca57914825a8dcebc04e0114147fe32fc7de1dcabb  ktistec.initd
b8971fe3a504df6173015a33a8edd64d74144128a1247328067fe82bee796d5faa55fa00de01690fedd7a027fb55e584b98b20277faa4140b913f52e4ec094e3  ktistec.confd
"
